<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="com.ncp.model.biz.bbs.ArticleProcess"%>
<%@page import="com.ncp.model.entity.comment.Articlebean"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%
int nowPage=1;
int showPages=5;
int size=2;
ArticleProcess ap=new ArticleProcess();
int PageCount=ap.getArticclePageCount();
String now=request.getParameter("nowPage");
if(now!=null){
	nowPage=Integer.parseInt(now);
}
ArrayList<Articlebean> alist=ap.getArticle(nowPage);
String userLoginName = (String)request.getSession().getAttribute("LoginName");
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'showarticle.jsp' starting page</title>
    <script charset="utf-8" src="kindeditor/kindeditor.js"></script>
	<script charset="utf-8" src="kindeditor/lang/zh_CN.js"></script>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  <link rel="stylesheet" href="css/common.css" type="text/css"/>
  				 <style type="text/css">
			 #page_1 div{line-height:32px; font-size:12px;}
			 
			 .title{ text-align:center;line-height:32px;}
			 .head_title div{ float:left}
			 #page_1 div .one a , #page div .two a{    display: block; height: 30px; overflow: hidden;}
			 .common{border-right:1px solid #ccc;}
			 .a{ width:350px; text-align:left; padding:0 34px;}
			 .b{ width:70px;}
			 .c{ width:70px;}
			 .d{ width:70px;}
			 .e{ width:160px;border-right:0;}
			 .one div{ float:left}
			 .two div{ float:left}
			 .two{ background:#eee;}
			 a{ color:#000;}
			 a:hover{ color:#999;}
			 .head_title{ background:#eee;}
			 </style>
  <script type="text/javascript">
        var editor;
        KindEditor.ready(function(K) {
                editor = K.create('textarea[name="content"]');
        });

        function check(){
   			var title=document.getElementById("title").value;
   			if(title.length==0){
   				document.getElementById("title").onfocus;
   				document.getElementById("tempty").innerHTML="<font color='red'>标题不能为空</font>";
   				return false;
   			}else{
   				document.getElementById("tempty").innerHTML="";
   				return true;
   			}
   			
   		}
  </script>

  <head>
  
  <body>
  <div id="allpage"><jsp:include flush="true" page="../index/head.jsp"></jsp:include>
			
	<div id="page_1" style="width:800px; padding:0 40px; margin:0 auto;">
			<div width="100%" border="1">
			  <div class="head_title" style="height:32px;">
			    <div class="a common">标题</div>
			    <div class="b common">作者</div>
			    <div class="c common">浏览</div>
			    <div class="d common">回复</div>
			    <div class="e common">发帖时间</div>
			    <p style="clear:both"></p>
			  </div>
			 <%
			 for(int i=0;i<alist.size();i++){
				 Articlebean ab=alist.get(i);
				 if(i%2==0){
					%>
			   <div class="one" style="height:32px;">
			    <div class="a common"><a href="ShowReplyServlet?id=<%=ab.getId() %>"><%=ab.getTitle() %></a></div>
			    <div class="b common"><%=ab.getUsername() %></div>
			    <div class="c common"><%=ab.getClicks() %></div>
			    <div class="d common"><%=ab.getReplycount(ab.getId()) %></div>
			    <div class="e common"><%=ab.getPdate() %></div>
			  </div>
					<%
				 }else{
					 %>
			  <div class="two" style="height:32px;">
			    <div class="a common"><a href="ShowReplyServlet?id=<%=ab.getId() %>"><%=ab.getTitle() %></a></div>
			    <div class="b common"><%=ab.getUsername() %></div>
			    <div class="c common"><%=ab.getClicks() %></div>
			    <div class="d common"><%=ab.getReplycount(ab.getId()) %></div>
			    <div class="e common"><%=ab.getPdate() %></div>
			  </div>
					 <%
				 }
			 }
			 %>
			
			 <div id="page">
					<ul>
					
					<% 
					if(nowPage>1){
						%><li><a href="pages/bbs/showarticle.jsp?nowPage=<%= nowPage-1 %>" class="page">上一页</a></li><%
					}
					
					
					
						if(PageCount>=showPages){
							if(nowPage-size<=0){
								for(int i=1;i<=showPages;i++){
									%>
									
									<li><a href="pages/bbs/showarticle.jsp?nowPage=<%=i %>" class="num" ><%=i %></a></li>
									<%
								}
								%><li>...</li><%
							}else if(nowPage+size<PageCount){
								for(int i=nowPage-size;i<=nowPage+size;i++){
									%>
									
									<li><a href="pages/bbs/showarticle.jsp?nowPage=<%=i %>" class="num" ><%=i %></a></li>
									<%
								}
								%><li>...</li><%
							}else if(nowPage+size>=PageCount){
								for(int i=PageCount-showPages+1;i<=PageCount;i++){
									%>
									
									<li><a href="pages/bbs/showarticle.jsp?nowPage=<%=i %>" class="num" ><%=i %></a></li>
									<%
								}
							}
						}else if(PageCount<=showPages){
							for(int i=1;i<=PageCount;i++){
								%>
								<li><a href="pages/bbs/showarticle.jsp?nowPage=<%=i %>" class="num" ><%=i %></a></li>
								<%
							}
						}
						
						if(nowPage<PageCount){
							%>
							<li><a href="pages/bbs/showarticle.jsp?nowPage=<%=nowPage+1 %>" class="page" ">下一页</a></li>
							<%
						}
						%>
						<li>共<%= ap.getArticclePageCount()%>页&emsp;</li>
							
							<form action="pages/bbs/showarticle.jsp" method="get">
							<li><input type="submit" value="跳到"/></li>
							<li><input id="skip" type="text" name="nowPage" style="width:30px; border:1px solid #CCC;" value="<%=nowPage %>"/></li>
							<li>页</li>
							</form>
					</ul>
		</div>
			   
			   				  <div>
				    <div height="34">
				    			    <%
			    if(userLoginName==null){
			    	%>
			    	您还没有登录!
			    	<form action="LoginServlet" method="post" >
			    	<label>登录账号&emsp;<input type="text" id="userLoginName" name="userLoginName" style="width:115px; height:20px; line-height:20px; color:#666; border:1px solid #CCC; margin-top:20px;" /></label>
			    	<label>登录密码&emsp;<input type="password" id="passWord" name="passWord" style="width:115px; height:20px; line-height:20px; color:#666; border:1px solid #CCC; margin-top:10px;" /></label><br>
			    	<label>验&nbsp;证&nbsp;码&emsp;<input type="text" id="inputCheckCode" name="inputCheckCode" value="" style="width:64px; height:20px; line-height:20px; color:#666; border:1px solid #CCC; margin-top:10px;" /></label>
			    	<img alt="请输入四位的验证码" src="pictureCheckCodeServlet" id="pictureCheckCode">
					<a href="javascript:changeImg();" title="更换一张验证码图片">看不清，换一张</a>
			    	<input type="submit" value="登录">
			    	</form>
			    	<%
			    }
			    %>
			    <div id="page_1_1" style="text-align:left;">
				    <form onsubmit="return check();" action="ArticleProcessServlet" method="post">
				    <label>标题<input onblur="check()" type="text" id="title" style="width:400px; height:30px; line-height:30px;margin-left:20px;border:1px solid #ccc;" /><span id="tempty"></span></label><br>
				      <textarea style="border:1px solid #ccc; resize:none; margin:20px; width:700px;" name="content" cols="45" rows="5">
				      </textarea>
				      <input type="submit" value="提交" style="cursor:pointer; background:#aaa; color:#fff; border:2px solid #ccc;" />
			         <input type="reset" value="重置" style="cursor:pointer;text-align:center; background:#aaa; color:#fff; border:2px solid #ccc; width:60px; height:24px;" />
				    </form>
				    </div>
				    
				  </div>
				  
			  </div>
			</div>
</div>
</body>
</html>
